/*****************************************************************************
 *   Copyright 2005 Tim A Wang
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 ****************************************************************************/
package com.jb.web.model.css;

public class BorderStyle extends BoxStyle {
    protected String bottomColor;
    protected String bottomStyle;
    protected String leftColor;
    protected String leftStyle;
    protected String rightColor;
    protected String rightStyle;
    protected String topColor;
    protected String topStyle;
    private String borderStyle;
    private String borderWidth;
    private String color;
    private String mMarginBottom;
    private String mMarginLeft;
    private String mMarginRight;
    private String mMarginTop;
    private String mPaddingBottom;
    private String mPaddingLeft;
    private String mPaddingRight;
    private String mPaddingTop;
    private String margine;
    private String padding;

    public void setBorderStyle(String borderStyle) {
        this.borderStyle = borderStyle;
    }

    public String getBorderStyle() {
        return borderStyle;
    }

    public void setBorderWidth(String borderWidth) {
        this.borderWidth = borderWidth;
    }

    public String getBorderWidth() {
        return borderWidth;
    }

    public void setBottomColor(String bottomColor) {
        this.bottomColor = bottomColor;
    }

    public String getBottomColor() {
        return bottomColor;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public String getColor() {
        return color;
    }

    public void setLeftColor(String leftColor) {
        this.leftColor = leftColor;
    }

    public String getLeftColor() {
        return leftColor;
    }

    public void setMarginBottom(String mMarginBottom) {
        this.mMarginBottom = mMarginBottom;
    }

    public String getMarginBottom() {
        return mMarginBottom;
    }

    public void setMarginRight(String mMarginRight) {
        this.mMarginRight = mMarginRight;
    }

    public String getMarginRight() {
        return mMarginRight;
    }

    public String getMarginTop() {
        return mMarginTop;
    }

    public void setMargine(String margine) {
        this.margine = margine;
    }

    public String getMargine() {
        return margine;
    }

    public void setPadding(String padding) {
        this.padding = padding;
    }

    public String getPadding() {
        return padding;
    }

    public void setPaddingBottom(String mPaddingBottom) {
        this.mPaddingBottom = mPaddingBottom;
    }

    public String getPaddingBottom() {
        return mPaddingBottom;
    }

    public void setPaddingLeft(String mPaddingLeft) {
        this.mPaddingLeft = mPaddingLeft;
    }

    public String getPaddingLeft() {
        return mPaddingLeft;
    }

    public void setPaddingRight(String mPaddingRight) {
        this.mPaddingRight = mPaddingRight;
    }

    public String getPaddingRight() {
        return mPaddingRight;
    }

    public void setPaddingTop(String mPaddingTop) {
        this.mPaddingTop = mPaddingTop;
    }

    public String getPaddingTop() {
        return mPaddingTop;
    }

    public void setRightColor(String rightColor) {
        this.rightColor = rightColor;
    }

    public String getRightColor() {
        return rightColor;
    }

    public String getStyle() {
        StringBuffer buffer = new StringBuffer("");

        if (borderStyle != null) {
            buffer.append(addProperty("border-style", borderStyle, null));
        } else {
            buffer.append(addProperty("border-top-style", topStyle, null));
            buffer.append(addProperty("border-left-style", leftStyle, null));
            buffer.append(addProperty("border-right-style", rightStyle, null));
            buffer.append(addProperty("border-bottom-style", bottomStyle, null));
        }

        if (borderWidth != null) {
            buffer.append(addProperty("border-width", borderWidth, null));
        } else {
            buffer.append(addProperty("border-top-width", top, null));
            buffer.append(addProperty("border-left-width", left, null));
            buffer.append(addProperty("border-right-width", right, null));
            buffer.append(addProperty("border-bottom-width", bottom, null));
        }

        if (color != null) {
            buffer.append(addProperty("border-color", color, null));
        } else {
            buffer.append(addProperty("border-top-color", topColor, null));
            buffer.append(addProperty("border-left-color", leftColor, null));
            buffer.append(addProperty("border-right-color", rightColor, null));
            buffer.append(addProperty("border-bottom-color", bottomColor, null));
        }

        if (margine != null) {
            buffer.append(addProperty("margin", margine, null));
        } else {
            buffer.append(addProperty("margin-top", mMarginTop, null));
            buffer.append(addProperty("margin-left", mMarginLeft, null));
            buffer.append(addProperty("margin-right", mMarginRight, null));
            buffer.append(addProperty("margin-bottom", mMarginBottom, null));
        }

        if (padding != null) {
            buffer.append(addProperty("padding", padding, null));
        } else {
            buffer.append(addProperty("padding-top", mPaddingTop, null));
            buffer.append(addProperty("padding-left", mPaddingLeft, null));
            buffer.append(addProperty("padding-right", mPaddingRight, null));
            buffer.append(addProperty("padding-bottom", mPaddingBottom, null));
        }

        return buffer.toString();
    }

    public void setStyleValue(String pValue) {
        if (pValue.indexOf("border-style") != -1) {
            borderStyle = pValue.substring(pValue.indexOf(":") + 1);
            topStyle = borderStyle;
            rightStyle = borderStyle;
            leftStyle = borderStyle;
            bottomStyle = borderStyle;
        }

        if (pValue.indexOf("border-top-style") != -1) {
            topStyle = pValue.substring(pValue.indexOf(":") + 1);
        }

        if (pValue.indexOf("border-right-style") != -1) {
            rightStyle = pValue.substring(pValue.indexOf(":") + 1);
        }

        if (pValue.indexOf("border-left-style") != -1) {
            leftStyle = pValue.substring(pValue.indexOf(":") + 1);
        }

        if (pValue.indexOf("border-bottom-style") != -1) {
            bottomStyle = pValue.substring(pValue.indexOf(":") + 1);
        }

        if (pValue.indexOf("border-color") != -1) {
            topColor = pValue.substring(pValue.indexOf(":") + 1);
            rightColor = pValue.substring(pValue.indexOf(":") + 1);
            leftColor = pValue.substring(pValue.indexOf(":") + 1);
            bottomColor = pValue.substring(pValue.indexOf(":") + 1);
        }

        if (pValue.indexOf("border-left-color") != -1) {
            leftColor = pValue.substring(pValue.indexOf(":") + 1);
        }

        if (pValue.indexOf("border-top-color") != -1) {
            topColor = pValue.substring(pValue.indexOf(":") + 1);
        }

        if (pValue.indexOf("border-bottom-color") != -1) {
            bottomColor = pValue.substring(pValue.indexOf(":") + 1);
        }

        if (pValue.indexOf("border-right-color") != -1) {
            rightColor = pValue.substring(pValue.indexOf(":") + 1);
        }

        if (pValue.indexOf("border-width") != -1) {
            borderWidth = pValue.substring(pValue.indexOf(":") + 1);
            left = pValue.substring(pValue.indexOf(":") + 1);
            top = pValue.substring(pValue.indexOf(":") + 1);
            bottom = pValue.substring(pValue.indexOf(":") + 1);
            right = pValue.substring(pValue.indexOf(":") + 1);
        }

        if (pValue.indexOf("border-left-width") != -1) {
            left = pValue.substring(pValue.indexOf(":") + 1);
        }

        if (pValue.indexOf("border-top-width") != -1) {
            top = pValue.substring(pValue.indexOf(":") + 1);
        }

        if (pValue.indexOf("border-bottom-width") != -1) {
            bottom = pValue.substring(pValue.indexOf(":") + 1);
        }

        if (pValue.indexOf("border-right-width") != -1) {
            right = pValue.substring(pValue.indexOf(":") + 1);
        }

        if (pValue.indexOf("margin:") != -1) {
            margine = pValue.substring(pValue.indexOf(":") + 1);
            mMarginTop = margine;
            mMarginLeft = margine;
            mMarginRight = margine;
            mMarginBottom = margine;
        }

        if (pValue.indexOf("margin-top") != -1) {
            mMarginTop = pValue.substring(pValue.indexOf(":") + 1);
        }

        if (pValue.indexOf("margin-left") != -1) {
            mMarginLeft = pValue.substring(pValue.indexOf(":") + 1);
        }

        if (pValue.indexOf("margin-right") != -1) {
            mMarginRight = pValue.substring(pValue.indexOf(":") + 1);
        }

        if (pValue.indexOf("margin-bottom") != -1) {
            mMarginBottom = pValue.substring(pValue.indexOf(":") + 1);
        }

        if (pValue.indexOf("padding:") != -1) {
            padding = pValue.substring(pValue.indexOf(":") + 1);
            mPaddingBottom = padding;
            mPaddingRight = padding;
            mPaddingLeft = padding;
            mPaddingTop = padding;
        }

        if (pValue.indexOf("padding-bottom") != -1) {
            mPaddingBottom = pValue.substring(pValue.indexOf(":") + 1);
        }

        if (pValue.indexOf("padding-right") != -1) {
            mPaddingRight = pValue.substring(pValue.indexOf(":") + 1);
        }

        if (pValue.indexOf("padding-left") != -1) {
            mPaddingLeft = pValue.substring(pValue.indexOf(":") + 1);
        }

        if (pValue.indexOf("padding-top") != -1) {
            mPaddingTop = pValue.substring(pValue.indexOf(":") + 1);
        }
    }

    public void setTopColor(String topColor) {
        this.topColor = topColor;
    }

    public String getTopColor() {
        return topColor;
    }

    public static void main(String[] args) {
        String colorStr = "border-style:solid;border-top-width:1pt;border-left-width:1pt;border-right-width:1pt;border-bottom-width:1pt;border-top-color:663300;border-left-color:3300FF;border-right-color:3300FF;border-bottom-color:FF00CC;";
        BorderStyle borderStyle = new BorderStyle();
        borderStyle.setStyle(colorStr);
        System.out.println(borderStyle.getStyle());
    }

    public void setBottomStyle(String bottomStyle) {
        this.bottomStyle = bottomStyle;
    }

    public String getBottomStyle() {
        return bottomStyle;
    }

    public void setLeftStyle(String leftStyle) {
        this.leftStyle = leftStyle;
    }

    public String getLeftStyle() {
        return leftStyle;
    }

    public void setMarginLeft(String mMarginLeft) {
        this.mMarginLeft = mMarginLeft;
    }

    public String getMarginLeft() {
        return mMarginLeft;
    }

    public void setMarginTop(String mMarginTop) {
        this.mMarginTop = mMarginTop;
    }

    public void setRightStyle(String rightStyle) {
        this.rightStyle = rightStyle;
    }

    public String getRightStyle() {
        return rightStyle;
    }

    public void setTopStyle(String topStyle) {
        this.topStyle = topStyle;
    }

    public String getTopStyle() {
        return topStyle;
    }

    public String toString() {
        return "BorderStyle";
    }
}
